﻿<%@ Page Language="C#" MasterPageFile="~/Main.master" CodeBehind="List.aspx.cs" Inherits="DD_Extensions.List" %>
<%@ Import Namespace="NotAClue" %>

<%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>

<asp:Content ID="HeadContent" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server" >
	<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true">
		<DataControls>
			<asp:DataControlReference ControlID="GridView1" />
		</DataControls>
	</asp:DynamicDataManager>

	<%--<h2 class="DDSubHeader"><%= table.DataContextPropertyName.ToTitleFromPascal() %></h2>--%>
	<h2 class="DDSubHeader"><%= table.DisplayName %></h2>

	<asp:UpdatePanel ID="UpdatePanel1" runat="server">
		<ContentTemplate>
			<div class="DD">
				<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
					HeaderText="List of validation errors" CssClass="DDValidator" />
				<asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" CssClass="DDValidator" />
			</div>

			<fieldset id="Filters" class="DD" runat="server" clientidmode="Static">
				<legend>Filters</legend>

				<span id="MultiSearch" class="filter" runat="server" ClientIDMode="Static" visible="false">
					<asp:Label ID="Label1" runat="server" Text="Search" AssociatedControlID="txbMultiColumnSearch" />
					<asp:TextBox ID="txbMultiColumnSearch" CssClass="DDFilter" ClientIDMode="Static" runat="server" />
					<asp:Button ID="btnMultiColumnSearchSubmit" CssClass="DDFilter" runat="server" ClientIDMode="Static" 
						Text="Search" onclick="btnMultiColumnSearch_Click" />
					<asp:Button ID="btnMultiColumnSearchClear" CssClass="DDFilter" runat="server" Text="Clear" 
						OnClick="btnMultiColumnSearch_Click" />&nbsp;
				</span>

				<asp:QueryableFilterRepeater runat="server" ID="FilterRepeater">
					<ItemTemplate>
						<span class="filter"><asp:DynamicFilter runat="server" ID="DynamicFilter" OnFilterChanged="DynamicFilter_FilterChanged" />&nbsp;</span>
					</ItemTemplate>
				</asp:QueryableFilterRepeater>

				<span id="ClearFiltersDiv" runat="server" class="filter RightAlign">
					<asp:Button ID="ClearFiltersButton" runat="server" Text="Clear all filters" 
						CssClass="DDFilter" OnClick="ClearFiltersButton_Click"/>
				</span>
			</fieldset>

			<table 
				id="GridViewHeader" 
				class="DDGridView DDTableHeader DDFakeHeader" 
				border="0" 
				rules="all" 
				cellspacing="0" 
				cellpadding="2" 
				runat="server">
				<tr class="th">
					<th class="InsertHeader">
						<asp:LinkButton ID="InsertHyperLinkText" CssClass="DDControl" CommandName="Insert" runat="server" />
					</th>
					<th class="ShowAllHeader">
						<span id="ExportSpan" runat="server" visible="false">
							<asp:ImageButton 
								ID="ExportImageButton" 
								ImageUrl="~/images/xlexport.png" 
								ToolTip="Export to Excel" 
								OnClick="btnExport_Click" 
								runat="server"/>&nbsp;
							<asp:LinkButton 
								ID="ExportLinkButton" 
								OnClick="btnExport_Click" 
								CssClass="TableHeadderText" 
								runat="server" 
								ToolTip="Export to Excel">
								Export to Excel
							</asp:LinkButton>
						</span>
						<asp:CheckBox 
							ID="ShowAllColumnsCheckbox" 
							runat="server" 
							CssClass="TableHeadderText" 
							Text="All columns" 
							Visible="false"
							ToolTip="All columns"/>                            
					</th>
				</tr>
			</table>

			<asp:GridView 
				ID="GridView1" 
				runat="server" 
				DataSourceID="GridDataSource" 
				EnablePersistedSelection="true" 
				AllowPaging="True" 
				AllowSorting="True" 
				CssClass="DDGridView" 
				GridLines="None" 
				PageSize="20"
				RowStyle-CssClass="td" 
				HeaderStyle-CssClass="th" 
				CellPadding="6" 
				OnPageIndexChanged="GridView1_PageIndexChanged">
				<Columns>
					<asp:TemplateField>
						<ItemTemplate>
							<asp:LinkButton ID="DetailsButton" runat="server" CssClass="DDControl" Text="Details" PostBackUrl='<%# table.GetActionPath(PageAction.Details, GetDataItem()) %>'  />
							<asp:LinkButton ID="EditButton" runat="server" CssClass="DDControl" Text="Edit" PostBackUrl='<%# table.GetActionPath(PageAction.Edit, GetDataItem()) %>' />
							<asp:LinkButton ID="DeleteButton" runat="server" CssClass="DDControl" Text="Delete" CommandName="Delete"  OnClientClick='return confirm("Are you sure you want to delete this item?");'/>
						</ItemTemplate>
						<ItemStyle Wrap="false" CssClass="nowrap" />
					</asp:TemplateField>
				</Columns>

				<HeaderStyle CssClass="th" />
				<PagerSettings Position="Bottom" />
				<PagerStyle CssClass="DDFooter" />
				<PagerTemplate>
					<asp:GridViewPager ID="GridViewPager1" runat="server" />
				</PagerTemplate>
				<EmptyDataTemplate>
					There are currently no items in this table.
				</EmptyDataTemplate>
				<RowStyle CssClass="td" />
				<SortedAscendingHeaderStyle CssClass="DDAscending" />
				<SortedDescendingHeaderStyle CssClass="DDDescending" />
			</asp:GridView>

			<asp:EntityDataSource 
				ID="GridDataSource" 
				runat="server" 
				EnableDelete="true" 
				onselecting="GridDataSource_Selecting"/>
			
			<asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">
				<asp:DynamicFilterExpression ControlID="FilterRepeater" />
			</asp:QueryExtender>
		</ContentTemplate>
	</asp:UpdatePanel>
</asp:Content>